package com.ruoyi.customer.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.customer.domain.Customer;
import com.ruoyi.customer.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.customer.mapper.CustomerLinkmaneMapper;
import com.ruoyi.customer.domain.CustomerLinkmane;
import com.ruoyi.customer.service.ICustomerLinkmaneService;

/**
 * 客户联系人Service业务层处理
 *
 * @author weixiao
 * @date 2022-11-27
 */
@Service
public class CustomerLinkmaneServiceImpl extends ServiceImpl<CustomerLinkmaneMapper, CustomerLinkmane> implements ICustomerLinkmaneService {

    @Autowired
    private ICustomerService customerService;
    /**
     * 查询客户联系人列表
     *
     * @param customerLinkmane 客户联系人
     * @return 客户联系人
     */
    @Override
    public List<CustomerLinkmane> selectCustomerLinkmaneList(CustomerLinkmane customerLinkmane) {
        return getBaseMapper().selectCustomerLinkmaneList(customerLinkmane);
    }

    @Override
    public boolean save(CustomerLinkmane entity) {
        Date date = new Date();
        entity.setInputTime(date);

        String username = SecurityUtils.getUsername();
        entity.setInputUser(username);

        Customer customer = customerService.getById(entity.getCustomerId());
        entity.setCustomerId(customer.getId());
        return super.save(entity);
    }

    @Override
    public boolean updateById(CustomerLinkmane entity) {
        Date date = new Date();
        entity.setInputTime(date);

        String username = SecurityUtils.getUsername();
        entity.setInputUser(username);

        Customer customer = customerService.getById(entity.getCustomerId());
        entity.setCustomerId(customer.getId());
        return super.updateById(entity);
    }
}
